<template>
  <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
    :pagination="ipagination" :loading="loading" @change="handleTableChange">
    <span slot="bizStatus" slot-scope="text">
      <a-tag color="green" v-if="text === 1">已使用</a-tag>
      <a-tag  color="" v-if="text === 0">未使用</a-tag>
      <a-tag color="red" v-if="text === -1">作废</a-tag>
      <a-tag color="orange" v-if="text === -2">已过期</a-tag>
    </span>
  </a-table>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'

export default {
  name: 'PosMemberCouponlist',
  mixins: [JeecgListMixin],
  components: {},
  //接受父组件向子组件传递的数据
  props: ['memberId'],
  data() {
    return {
      description: '客户优惠券信息',
      disableMixinCreated: true,
      // 表头
      columns: [
      {
          title: '优惠券活动编码',
          dataIndex: 'actCd',
          align: 'center',
        },
        {
          title: '优惠券名称',
          dataIndex: 'couponNm',
          align: 'center',
        },
        {
          title: '类型',
          dataIndex: 'couponType',
          align: 'center',
          customRender: (text, record) => {
            return text == 'zk' ? '折扣券' : '满减券'
          },
        },
        {
          title: '优惠内容',
          dataIndex: 'lessMoney',
          align: 'center',
          customRender: (text, record) => {
            if (text == 'zk') {
              return record.ruleVal + '折' + ' (' + '满' + record.lessMoney + '元' + '可用)'
            } else {
              return '减' + record.ruleVal + '元' + ' (' + '满' + record.lessMoney + '元' + '可用)'
            }
          },
        },
        {
          title: '有效期',
          dataIndex: 'validTime',
          align: 'center',
          customRender: (text, record) => {
            return record.validTime + '至' + record.endTime
          },
        },
        {
          title: '领取时间',
          dataIndex: 'getTime',
          align: 'center',
        },
        {
          title: '状态',
          dataIndex: 'bizStatus',
          align: 'center',
          scopedSlots: { customRender: 'bizStatus' }
        },
      ],
      url: {
        list: '/marketing/posMarketCouponGet/memberCouponPageList',
      },
    }
  },
  created() {
    this.loadData()
  },
  watch: {
    //子组件接收参数，并监听此值变化，一旦变化则初始化数据
    memberId(newVal, oldVal) {
      this.dataSource = []
      console.log('===oldVal===', oldVal)
      console.log('===newVal===', newVal)
      this.loadData()
    }
  },
  methods: {
    loadData(arg) {
      if (arg === 1) {
        this.ipagination.current = 1
      }
      console.log('===memberId===', this.memberId)
      //主子表分开维护，生成的代码子表的分页改为真实的分页
      this.queryParam.memberId = this.memberId
      getAction(this.url.list, {
        memberId: this.memberId,
        showAll: true,
        pageNo: this.ipagination.current,
        pageSize: this.ipagination.pageSize,
      }).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
        } else {
          this.dataSource = null
        }
      })
      //主子表分开维护，生成的代码子表的分页改为真实的分页
    },
  },
}
</script>
<style scoped>
</style>